<?php

namespace App\Models\Traits;

use App\Models\OperateLog;
use App\Models\User\User;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Facades\Auth;

trait HasCreator
{
    public function creator() : BelongsTo
    {
        return $this->belongsTo(User::class, 'creator_id');
    }

    protected static function bootHasCreator()
    {
        static::creating(function ($model) {
            $model->creator_id = Auth::id();
        });
    }
}
